Secretary of Defense Caspar W. Weinberger announced today that President Reagan will visit China in April, a long-sought diplomatic achievement that allowed Weinberger to end three days of talks in Peking on a cheerful note.

Weinberger said Reagan's election-year visit will follow a January trip to Washington by Chinese Premier Zhao Ziyang. One U.S. official said the summit meetings will help China "defang the mythical dragon," a reference to Chinese suspicions of Reagan because of his support for Taiwan.

In addition to assuring the summit meetings, Weinberger said his talks had "secured the basis for a continuing relationship" with China. He came here seeking stronger military ties with Peking, which he said are important in the face of a Soviet military buildup in Asia. But he did not announce any new agreements in the fields of military exchanges, intelligence sharing or arms sales.

U.S. officials said that while they were pleased with the overall tone of the talks, the Chinese remain suspicious of American motives and extremely cautious about entering into the kind of military cooperation the United States wants. In particular, China is still waiting for new regulations that would allow it to import sophisticated technology, with potential military applications, from the United States.

The guidelines have been drafted, but Pentagon officials are insisting that China promise not to pass the technology to other countries, such as North Korea--an insistence Chinese officials are reported to regard as a possible infringement of their sovereignty.

Similarly, China wants to import some U.S. weapons, according to officials here, and Weinberger said his discussions could "mature, I think very quickly, into actual transfers of weapon systems if that is what the Chinese want." But the Chinese are concerned that arms trade with the United States might be interpreted as a tacit assent for U.S. arms sales to Taiwan.

Although the public complaints on U.S.-Taiwan relations were relatively mild this week, Communist Party Chairman Deng Xiaoping raised the issue in private conversation with Weinberger this morning that was "predictable, tough and full of warnings," according to one knowledgeable official.

U.S. officials here say they hope that an exchange of visits by Reagan and Zhao will convince the Chinese that the Taiwan issue is manageable and that other cooperation can take place while the United States continues to sell arms to the country that China regards as a wayward province.

White House spokesman Larry Speakes, asked about the U.S. relationship with Taiwan, quoted from a statement Reagan made last year that "the Taiwan question is a matter for the Chinese people on both sides of the Taiwan Strait to resolve. We will not interfere in this matter. . . At the same time, we have an abiding interest and concern that any resolution be peaceful." He noted that Reagan also is committed to maintaining "a full range of contacts between the United States and the people of Taiwan."

Weinberger mentioned Reagan frequently during toasts and private conversations, officials said, to convince the Chinese that despite his friendship with Taiwan, the president does support warmer relations with China. And Weinberger said he believes the two countries' similar concerns, especially regarding the Soviet Union, outweigh their differences.

"We have divergent views of course in some areas," Weinberger said. "But our positions on most important issues, I think are close, and both sides have been reassured on that."

Weinberger left Peking after his meeting with Deng and began two days of sightseeing and military inspections here and in Shanghai. Weinberger said he expects talks will continue on military exchanges and weapon sales.

China is still interested in antitank and antiaircraft missiles, Weinberger said, as well as other systems, but it is said to want more advanced systems than it requested in 1981 when the question first arose. Talks were suspended then after the United States announced an arms package for Taiwan.

U.S. officials say they are not certain what weapons China wants to buy.